<template>
    <div>
        <header class="pr white" style="padding: 45px 0px 40px;">
            <img src="../../assets/images/7.jpg" class="displayB centerauto shadowB" style="max-width: 70%;margin: 0px auto;padding: 10px;background: #fff;" />
        </header>
        <van-cell-group>
            <van-cell-group>
                <van-radio-group v-model="isType" @change="changeFun">
                    <div class="van-cell flexbox spacebetween">
                        <p style="width: 70px;">
                            充值方式：
                        </p>
                        <div class="clearfix text-center" style="width: calc(100% - 70px);font-size: 13px;">
                            <van-radio name="1" style="width: 33.3%;float:left;" checked-color="#d92626" >微信</van-radio>
                            <van-radio name="2" style="width: 33.3%;float:left;" checked-color="#d92626" >支付宝</van-radio>
                            <van-radio name="3" style="width: 33.3%;float:left;" checked-color="#d92626" >USD充值</van-radio>
                        </div>
                    </div>
                </van-radio-group>
            </van-cell-group>
            <div class="text-left padding_lr15" style="border-bottom: 1px solid rgb(235, 237, 240,.5);" v-show="(isType == 1) || (isType == 2)">
                <span>接收二维码：</span>
                <img :src="nowcode" width="80" style="vertical-align: middle;padding: 5px 0;" @click="popShow = true" />
            </div>
            <div class="text-left padding_lr15" style="border-bottom: 1px solid rgb(235, 237, 240,.5);padding: 15px;" v-show="isType == 3">
                <span>收款账户：</span>
                <div style="display: inline-block;vertical-align: bottom;overflow: hidden;height: 24px;">
                    <img src="../../assets/images/7.jpg" width="173px" style="vertical-align: middle;" />
                </div>
            </div>
            <van-field v-model="money" type="number" label="充值金额￥：" placeholder="请输入" />
            <van-field v-model="message" label="备注：" type="textarea" placeholder="" rows="3" autosize/>
        </van-cell-group>
        <div class="text-center margin_t50">
            <van-button type="primary" class="width_80p btn_size_40" @click="onSubmit">{{(isType == 3) ? '跳转支付页面' : '充 值'}}</van-button>
        </div>
        <!-- 放大二维码 -->
        <van-popup v-model="popShow">
            <img :src="nowcode" width="300" alt="" />
        </van-popup>
    </div>
</template>
<script>

    import '@/assets/css/main.css'
    export default {
        data(){
            return{
                isType: '1',
                money: '',
                message: '',
                password: '',
                codeArr: {},
                nowcode: '',
                popShow: false,
            }
        },
        methods: {
            init(){
                var _this = this;
                this.$httpGet('/api/index/Personal_center/getSystemTwoCode').then(response => {
                    
                    if(response.code == 200){

                        _this.codeArr = response.msg;
                        _this.nowcode = _this.codeArr.s_weixin;

                    }else{
                        
                        _this.$toast(response.msg);
                    }

                });
            },
            changeFun(val){
                var _this = this;
                if(val == 1){
                    this.nowcode = this.codeArr.s_weixin;
                }else if(val == 2){
                    this.nowcode = this.codeArr.s_alipay;
                }
            },
            //提交
            onSubmit(){
                var _this = this;

                if(!_this.money){
                    _this.$toast('请输入充值金额');
                    return;
                }
                if(!_this.message){
                    _this.$toast('请输入备注');
                    return;
                }
                if(_this.isType == 3){
                    this.$dialog.alert({
                        message: '该卡不支持USD业务'
                    }).then(() => {
                        
                    });
                    return;
                }

                this.$httpPost('/api/index/Personal_center/userRecharge',{
                    'u_id': window.localStorage.u_id,
                    'o_type': _this.isType,
                    'o_money_rmb': _this.money,
                    'o_remark': _this.message,
                }).then(response => {
                    
                    if(response.code == 200){

                        _this.$toast(response.msg);

                        setTimeout(() => {
                            _this.$router.push({path:'/rechargerecord'});
                        }, 2000);

                    }else{
                        
                        _this.$toast(response.msg);
                    }

                });
            },
        },
        mounted(){
            this.init();
        },
    }
</script>